package ren.kane.phoenix.util.io;

import java.io.CharArrayWriter;
import java.io.IOException;

/**
 * @author renrk(1275) on 2019-08-13 11:06 AM
 **/
public class CharArrayWriterTest {

    private static final int LEN = 5;
    private static final char[] ARRAY_LETTERS = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

    private static void testCharArrayWriter() {
        try {
            CharArrayWriter charArrayWriter = new CharArrayWriter();
            charArrayWriter.write('A');
            charArrayWriter.write("BC");
            charArrayWriter.write(ARRAY_LETTERS, 3, 5);
            charArrayWriter.append('0').append("123456789").append(String.valueOf(ARRAY_LETTERS), 8, 12);
            System.out.printf("charArrayWriter=%s\n", charArrayWriter);

            System.out.printf("size=%s\n", charArrayWriter.size());

            char[] buf = charArrayWriter.toCharArray();
            System.out.printf("buf=%s\n", String.valueOf(buf));

            CharArrayWriter caw = new CharArrayWriter();
            charArrayWriter.writeTo(caw);
            System.out.printf("caw=%s\n", caw);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        testCharArrayWriter();
    }
}
